package com.zy.Conterller;


import com.zy.pojo.Supper;
import com.zy.service.SupperService;
import com.zy.vo.ResultVo;
import com.zy.vo.Supper.SupperVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/supper")
public class SupperController {

    @Resource
    private SupperService supperService;
    @GetMapping("list")
    public ResultVo select(){

        return ResultVo.success(supperService.getSupperList());
    }

    @GetMapping("/pagelist/{pageSize}/{pageNo}")
    @RequiresPermissions("supplier:list")
    public ResultVo getSupperList(@PathVariable Integer pageSize, @PathVariable Integer pageNo, SupperVo supperVo){

        return ResultVo.success(supperService.getPage(pageNo,pageSize,supperVo));
    }

    @PostMapping("/supperadd")
    @RequiresPermissions("supplier:add")

    public ResultVo add(@RequestBody Supper supper, HttpSession session){

        try{
            supperService.getsupperadd(supper);
            return ResultVo.success("角色添加成功!");
        }catch (Exception e){
            return ResultVo.fail("角色添加失败!",e);
        }
    }

    @PostMapping("/supperupdate")
    @RequiresPermissions("supplier:update")

    public  ResultVo update(@RequestBody Supper supper, HttpSession session){
        try {
            supperService.getsupperupdate(supper);
            return ResultVo.success("角色修改成功!");
        }catch (Exception e){
             return  ResultVo.fail("角色修改失败!",e);
        }
    }

    @GetMapping("supperdel/{id}")
    @RequiresPermissions("supplier:del")

    public ResultVo del(@PathVariable String id){
        try {
            supperService.getsupperdel(Integer.parseInt(id));
            return ResultVo.success("删除成功!");
        }catch (Exception e){
            return ResultVo.fail("删除失败！！",e);
        }
    }

}
